package com.ktjiaoyu.crm.service.impl;


import com.ktjiaoyu.crm.entity.Plan;
import com.ktjiaoyu.crm.repository.PlanRepository;
import com.ktjiaoyu.crm.service.IPlanService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 实现类---客户开发计划
 * @author Administrator
 */
@Service(value = "planService")
public class PlanServiceImpl implements IPlanService {
    @Resource
    private PlanRepository planRepository;

    /**
     * 通过机会id查找相应的开发计划
     *
     * @param chcId 机会id
     * @return list
     */
    @Override
    public List<Plan> findPlanByChcId(Long chcId) {
        return planRepository.findPlanByChance_ChcId(chcId);
    }

    /**
     * 保存
     *
     * @param plan 计划
     */
    @Override
    public void save(Plan plan) {
        this.planRepository.save(plan);
    }

    /**
     * 修改计划
     *
     * @param plaTodo 执行计划
     * @param plaId   计划Id
     */
    @Override
    public void updatePlaTodoById(String plaTodo, Long plaId) {
        this.planRepository.updatePlaTodoByPlaId(plaTodo, plaId);
    }

    /**
     * 修改计划结果
     *
     * @param plaResult 结果
     * @param plaId     机会Id
     */
    @Override
    public void updatePlaResultByPlaId(String plaResult, Long plaId) {
        this.planRepository.updatePlaResultByPlaId(plaResult, plaId);
    }

    /**
     * 删除计划
     *
     * @param plaId 计划Id
     */
    @Override
    public void delPlan(Long plaId) {
        //获得计划信息
        Plan plan = planRepository.getOne(plaId);
        //删除计划
        this.planRepository.delete(plan);
    }

    /**
     * 通过id查找计划
     *
     * @param plaId 计划Id
     * @return plan
     */
    @Override
    public Plan findPlanByPlaId(Long plaId) {
        return this.planRepository.getOne(plaId);
    }
}
